package cn.tang.tframe.mq.kafka.interceptor;

import cn.tang.tframe.common.annotation.BeanOrder;
import cn.tang.tframe.mq.IQtMessager;
import org.apache.kafka.clients.producer.ProducerInterceptor;
import org.apache.kafka.clients.producer.ProducerRecord;
import org.apache.kafka.clients.producer.RecordMetadata;

import java.util.Map;

/**
 * Created by tanghc on 17/2/4.
 */
@BeanOrder(order = -1)
public class QtMonitorKafkaProducerInterceptor implements ProducerInterceptor<IQtMessager,IQtMessager> {
	@Override
	public ProducerRecord<IQtMessager, IQtMessager> onSend(ProducerRecord<IQtMessager, IQtMessager> record) {
		if(record == null){
			return null;
		}
		IQtMessager value = record.value();
		if(value == null ){
			return record;
		}
		value.attach("monitor",new String("test kafka monitor"));

		return record;
	}

	@Override
	public void onAcknowledgement(RecordMetadata metadata, Exception exception) {

	}

	@Override
	public void close() {

	}

	@Override
	public void configure(Map<String, ?> configs) {

	}
}
